package com.xxy.services.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxy.pojo.Category;
import com.xxy.services.CategoryService;
import com.xxy.mapper.CategoryMapper;
import com.xxy.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
* @author Lenovo
* @description 针对表【category】的数据库操作Service实现
* @createDate 2024-01-28 17:09:27
*/
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
    implements CategoryService{


    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public void add(String category_name, String category_alias) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        categoryMapper.add(category_name,category_alias,id);
    }

    @Override
    public List<Category> getCategory(Integer id) {
        List<Category> list = categoryMapper.list(id);
        return list;
    }

    @Override
    public Category findById(Integer id) {

        return categoryMapper.findById(id);
    }

    @Override
    public void update(Category category) {
        category.setUpdate_time(LocalDateTime.now());
        categoryMapper.update(category);
    }

    @Override
    public void delete(Integer id) {
        categoryMapper.deleteById(id);
    }



}




